﻿Imports AugmentLib.Database
Imports System.Configuration.ConfigurationManager

Partial Class transact
    Inherits System.Web.UI.Page

    Private Sub LoadTransactor()
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()
        objDB.dbVariable.SQLString = "SELECT Name,StaffId FROM AW_Staff ORDER BY Name"
        objDB.FillData(TempDT, "AW_Staff", Database.SQLCommandType.NormalString)
        objDB.CloseConnection()

        ddlTransactor.DataSource = TempDT
        ddlTransactor.DataTextField = "Name"
        ddlTransactor.DataValueField = "StaffId"
        ddlTransactor.DataBind()
        ddlTransactor.Items.Insert(0, "-SELECT-")
        ddlTransactor.Items(0).Value = ""

    End Sub

    Private Sub LoadCoBroker()
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()
        objDB.dbVariable.SQLString = "SELECT (Name + '(' + AgencyName + ')') AS Name,CoBrokeId FROM AW_CoBroke ORDER BY Name"
        objDB.FillData(TempDT, "AW_CoBroke", Database.SQLCommandType.NormalString)
        objDB.CloseConnection()

        Dim NewRow As Data.DataRow
        NewRow = TempDT.NewRow
        NewRow.Item("Name") = "-SELECT-"
        NewRow.Item("CoBrokeId") = Guid.Empty
        TempDT.Rows.InsertAt(NewRow, 0)

        ddlCoBroke.DataSource = TempDT
        ddlCoBroke.DataTextField = "Name"
        ddlCoBroke.DataValueField = "CoBrokeId"
        ddlCoBroke.DataBind()
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("StaffId") Is Nothing Then
            Response.Redirect("Default.aspx")
        End If

        If Session("StaffType").ToString = "2" Or Session("StaffType").ToString = 4 Then
            Response.Redirect("Dashboard.aspx")
        Else
            lblStaffUID.Text = Session("StaffId").ToString
            lblStaffType.Text = Session("StaffType").ToString
        End If

        If Not Page.IsPostBack Then

            CBEBack.ConfirmText = "You are about to navigate away from this page. " & vbCrLf & "Changes will be discard!"

            lblAddress.Text = Session.Item("add").ToString
            'Session.Remove("add")
            lblProject.Text = Session.Item("project").ToString
            'Session.Remove("project")
            lblPropertyType.Text = Session.Item("propertyType").ToString
            'Session.Remove("propertyType")
            lblLASQFT.Text = Session.Item("LASQ").ToString
            'Session.Remove("LASQ")
            lblBUSQFT.Text = String.Format("{0:#,##0.00}", Session.Item("BUSQ").ToString)
            'Session.Remove("BUSQ")
            lblPropertyUID.Text = Session.Item("propertyid").ToString
            'Session.Remove("propertyid")

            GetddlTransactType(Session.Item("tp").ToString)
            'Session.Remove("tp")
            LoadTransactor()
            LoadCoBroker()
        End If

    End Sub

    Private Sub GetddlTransactType(ByVal TransType As String)

        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable
        Dim TransTypeDT As New Data.DataTable

        If lblStaffType.Text = "2" Then         '--REN
            If TransType = "1" Then             '--Sales
                Dim NewRow As Data.DataRow
                NewRow = TransTypeDT.NewRow
                NewRow.Item("TransType") = "Sale By Owner"
                NewRow.Item("TransTypeValue") = "3"
                TransTypeDT.Rows.InsertAt(NewRow, 0)

                NewRow = TransTypeDT.NewRow
                NewRow.Item("TransType") = "Not For Sale"
                NewRow.Item("TransTypeValue") = "2"
                TransTypeDT.Rows.InsertAt(NewRow, 0)

                NewRow = TransTypeDT.NewRow
                NewRow.Item("TransType") = "Sale"
                NewRow.Item("TransTypeValue") = "1"
                TransTypeDT.Rows.InsertAt(NewRow, 0)
            Else                                '--Rent
                Dim NewRow As Data.DataRow
                NewRow = TransTypeDT.NewRow
                NewRow.Item("TransType") = "Rent By Owner"
                NewRow.Item("TransTypeValue") = "6"
                TransTypeDT.Rows.InsertAt(NewRow, 0)

                NewRow = TransTypeDT.NewRow
                NewRow.Item("TransType") = "Not For Rent"
                NewRow.Item("TransTypeValue") = "5"
                TransTypeDT.Rows.InsertAt(NewRow, 0)

                NewRow = TransTypeDT.NewRow
                NewRow.Item("TransType") = "Rent"
                NewRow.Item("TransTypeValue") = "4"
                TransTypeDT.Rows.InsertAt(NewRow, 0)
            End If


        Else                                    '--Boss/Administrator
            objDB.OpenConnection()
            'Edited by minginn @ 10/6/11 - to only display options if not yet have involve in transaction
            objDB.dbVariable.SQLString = "SELECT SListerId, RListerId, SRelistStatus, RRelistStatus FROM AW_Property WHERE PropertyId=@PropertyId"
            objDB.AddParameter("PropertyId", Data.SqlDbType.UniqueIdentifier, New Guid(lblPropertyUID.Text))
            objDB.FillData(TempDT, "AW_Property", Database.SQLCommandType.NormalString)
            objDB.CloseConnection()

            TransTypeDT.Columns.Add("TransType")
            TransTypeDT.Columns.Add("TransTypeValue")

            For Each row As Data.DataRow In TempDT.Rows
                If row.Item("SListerId").ToString <> "" And row.Item("SRelistStatus").ToString = "0" Then
                    Dim NewRow As Data.DataRow
                    NewRow = TransTypeDT.NewRow
                    NewRow.Item("TransType") = "Sale By Owner"
                    NewRow.Item("TransTypeValue") = "3"
                    TransTypeDT.Rows.InsertAt(NewRow, 0)

                    NewRow = TransTypeDT.NewRow
                    NewRow.Item("TransType") = "Not For Sale"
                    NewRow.Item("TransTypeValue") = "2"
                    TransTypeDT.Rows.InsertAt(NewRow, 0)

                    NewRow = TransTypeDT.NewRow
                    NewRow.Item("TransType") = "Sale"
                    NewRow.Item("TransTypeValue") = "1"
                    TransTypeDT.Rows.InsertAt(NewRow, 0)
                End If
                If row.Item("RListerId").ToString <> "" And row.Item("RRelistStatus").ToString = "0" Then
                    Dim NewRow As Data.DataRow
                    NewRow = TransTypeDT.NewRow
                    NewRow.Item("TransType") = "Rent By Owner"
                    NewRow.Item("TransTypeValue") = "6"
                    TransTypeDT.Rows.InsertAt(NewRow, 0)

                    NewRow = TransTypeDT.NewRow
                    NewRow.Item("TransType") = "Not For Rent"
                    NewRow.Item("TransTypeValue") = "5"
                    TransTypeDT.Rows.InsertAt(NewRow, 0)

                    NewRow = TransTypeDT.NewRow
                    NewRow.Item("TransType") = "Rent"
                    NewRow.Item("TransTypeValue") = "4"
                    TransTypeDT.Rows.InsertAt(NewRow, 0)
                End If
            Next
        End If

        'Edited by Tan Chin Teong @ 20121115 - to add in the delete capability
        'Allow delete only if there is no outstanding transaction
        objDB.OpenConnection()
        objDB.dbVariable.SQLString = "SELECT SListerId, RListerId, SRelistStatus, RRelistStatus FROM AW_Property WHERE PropertyId=@PropertyId1"
        objDB.AddParameter("PropertyId1", Data.SqlDbType.UniqueIdentifier, New Guid(lblPropertyUID.Text))
        TempDT.Clear()
        objDB.FillData(TempDT, "AW_Property", Database.SQLCommandType.NormalString)
        objDB.CloseConnection()
        For Each row As Data.DataRow In TempDT.Rows
            If (row.Item("SRelistStatus").ToString = "0" Or row.Item("SRelistStatus").ToString = "") And (row.Item("RRelistStatus").ToString = "0" Or row.Item("RRelistStatus").ToString = "") Then
                Dim NewRow As Data.DataRow
                NewRow = TransTypeDT.NewRow
                NewRow = TransTypeDT.NewRow
                NewRow.Item("TransType") = "Delete"
                NewRow.Item("TransTypeValue") = "7"
                TransTypeDT.Rows.InsertAt(NewRow, 10)
            End If
        Next
        '--- end edit by Tan Chin Teong

        ddlTransactType.DataSource = TransTypeDT
        ddlTransactType.DataTextField = "TransType"
        ddlTransactType.DataValueField = "TransTypeValue"
        ddlTransactType.DataBind()

    End Sub

    Protected Sub BtnTransact_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnTransact.Click
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        Dim TransactionUID As Guid = Guid.NewGuid
        Dim PropertyUID As Guid = New Guid(lblPropertyUID.Text)
        Dim TType As String = String.Empty
        Try
            objDB.OpenConnection()
            objDB.InitDbTrans()
            '-Insert into Transaction Table
            '(PropertyId, TransactionId,TransactDate,Remark,CreateDate, Status = 0
            '-aw_property
            'update R or S TransactionId, RRelistStatus or SRelistStatus to 1

            If ddlTransactType.SelectedValue = "1" Then
                'Sales
                objDB.dbVariable.SQLString = "INSERT INTO AW_SaleTransaction (TransactionId,PropertyId,TransactDate,TransactRemark,CreateDate,Status,CoBroke,CoBrokeId,TransactorId) VALUES (@TransactionId,@PropertyId,@TransactDate,@TransactRemark,@CreateDate,@Status,@CoBroke,@CoBrokeId,@TransactorId)"
                TType = "S"
            ElseIf ddlTransactType.SelectedValue = "4" Then
                'Rent
                objDB.dbVariable.SQLString = "INSERT INTO AW_RentTransaction (TransactionId,PropertyId,TransactDate,TransactRemark,CreateDate,Status,CoBroke,CoBrokeId,TransactorId,Renewed) VALUES (@TransactionId,@PropertyId,@TransactDate,@TransactRemark,@CreateDate,@Status,@CoBroke,@CoBrokeId,@TransactorId,@Renewed)"
                TType = "R"
            Else
                If objDB.dbVariable.objConn.State = Data.ConnectionState.Open Then
                    objDB.DbTransRollback()
                    objDB.CloseConnection()
                End If
                lblMsgError.Text = "Error to process. Please try to re-do"
                divError.Visible = True
                Exit Sub
            End If

            objDB.AddParameter("TransactionId", Data.SqlDbType.UniqueIdentifier, TransactionUID)
            objDB.AddParameter("PropertyId", Data.SqlDbType.UniqueIdentifier, PropertyUID)
            objDB.AddParameter("TransactDate", Data.SqlDbType.DateTime, DateTime.ParseExact(txtTransDate.Text, "dd-MMM-yyyy", Nothing))
            If txtRemark.Text.Trim = String.Empty Then
                objDB.AddParameter("TransactRemark", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("TransactRemark", Data.SqlDbType.NVarChar, txtRemark.Text)
            End If
            objDB.AddParameter("CreateDate", Data.SqlDbType.DateTime, Now)
            objDB.AddParameter("Status", Data.SqlDbType.TinyInt, 0)
            If ddlCoBroke.SelectedIndex = 0 Then
                objDB.AddParameter("CoBroke", Data.SqlDbType.TinyInt, 0)
                objDB.AddParameter("CoBrokeId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
            Else
                objDB.AddParameter("CoBroke", Data.SqlDbType.TinyInt, 1)
                objDB.AddParameter("CoBrokeId", Data.SqlDbType.UniqueIdentifier, New Guid(ddlCoBroke.SelectedValue))
            End If
            objDB.AddParameter("TransactorId", Data.SqlDbType.UniqueIdentifier, New Guid(ddlTransactor.SelectedValue))
            'edited by minginn @ 13/6/2011 - add in to differentiate trans from renew button or transact
            objDB.AddParameter("Renewed", Data.SqlDbType.TinyInt, 0)
            objDB.ExecuteQuery(False)
            Dim OId As Guid = Guid.NewGuid
            InsertTrans_Old(TType, objDB, OId)

            If ddlTransactType.SelectedValue = "1" Then
                'edited by minginn @ 20/6/2011 - to insert log into rem_old
                InsertIntoProperty_Old("S", "", 1, TransactionUID.ToString, PropertyUID.ToString, objDB)
                objDB.dbVariable.SQLString = "UPDATE AW_Property SET STransactionId=@TransactionId, SRelistStatus=@RelistStatus WHERE PropertyId=@PropertyId"
            Else
                'edited by minginn @ 20/6/2011 - to insert log into rem_old
                InsertIntoProperty_Old("R", "", 1, TransactionUID.ToString, PropertyUID.ToString, objDB)
                objDB.dbVariable.SQLString = "UPDATE AW_Property SET RTransactionId=@TransactionId, RRelistStatus=@RelistStatus WHERE PropertyId=@PropertyId"
            End If
            objDB.ClearParameter()
            objDB.AddParameter("TransactionId", Data.SqlDbType.UniqueIdentifier, TransactionUID)
            objDB.AddParameter("RelistStatus", Data.SqlDbType.TinyInt, 1)
            objDB.AddParameter("PropertyId", Data.SqlDbType.UniqueIdentifier, PropertyUID)
            objDB.ExecuteQuery()

            objDB.DbTransCommit()
            objDB.CloseConnection()

            If ddlTransactType.SelectedValue = "1" Then
                Session.Add("Tid", TransactionUID.ToString)
                Session.Add("Oid", OId.ToString)
                Response.Redirect("strans.aspx", False)
            Else
                Session.Add("Tid", TransactionUID.ToString)
                Session.Add("Oid", OId.ToString)
                Response.Redirect("rtrans.aspx", False)
            End If
        Catch ex As Exception
            If objDB.dbVariable.objConn.State = Data.ConnectionState.Open Then
                objDB.DbTransRollback()
                objDB.CloseConnection()
            End If
            lblMsgError.Text = ex.Message
            divError.Visible = True
        End Try

    End Sub

    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        Dim PropertyUID As Guid = New Guid(lblPropertyUID.Text)
        Dim CheckRentTransaction As New Data.DataTable
        Dim TransactionDT As New Data.DataTable
        Dim RRelistStatus As String = ""

        Try
            objDB.OpenConnection()
            'update RListStatus or SListStatus to 1 or 2, RRelistStatus or SRelistStatus to 2
            If ddlTransactType.SelectedValue = "2" Or ddlTransactType.SelectedValue = "3" Then
                'edited by minginn @ 9/6/2011 - Check if Rent Transaction is at status 1
                objDB.dbVariable.SQLString = "SELECT RRelistStatus FROM AW_Property WHERE PropertyId=@PropertyId"
                objDB.AddParameter("PropertyId", Data.SqlDbType.UniqueIdentifier, PropertyUID)
                objDB.FillData(CheckRentTransaction, "RentTrans", Database.SQLCommandType.NormalString)

                For Each ReadRow As Data.DataRow In CheckRentTransaction.Rows
                    RRelistStatus = ReadRow.Item("RRelistStatus").ToString
                Next

                If RRelistStatus = "1" Then
                    divError.Visible = True
                    lblMsgError.Text = "There is a pending RENT transaction. Please either COMPLETE the trasaction or ABORT the transaction"
                    ddlTransactType.SelectedIndex = -1
                    Exit Sub
                Else
                    objDB.InitDbTrans()

                    'edited by Tan Chin Teong @27/10/2012 - to trasact NFS/SBO to Transaction Status = 6
                    Dim TType As String = String.Empty
                    Dim TransactionUID As Guid = Guid.NewGuid
                    objDB.dbVariable.SQLString = "INSERT INTO AW_SaleTransaction (TransactionId,PropertyId,TransactDate,TransactRemark,CreateDate,Status,TransactorId) VALUES (@TransactionId,@PropertyId,@TransactDate,@TransactRemark,@CreateDate,@Status,@TransactorId)"
                    TType = "S"
                    objDB.AddParameter("TransactionId", Data.SqlDbType.UniqueIdentifier, TransactionUID)
                    objDB.AddParameter("PropertyId", Data.SqlDbType.UniqueIdentifier, PropertyUID)
                    objDB.AddParameter("TransactDate", Data.SqlDbType.DateTime, Now)

                    objDB.AddParameter("TransactRemark", Data.SqlDbType.NVarChar, "Not For Sale/Sales By Owner")
                    objDB.AddParameter("CreateDate", Data.SqlDbType.DateTime, Now)
                    objDB.AddParameter("Status", Data.SqlDbType.TinyInt, 6)
                    objDB.AddParameter("TransactorId", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text))
                    'add in to differentiate trans from renew button or transact
                    objDB.AddParameter("Renewed", Data.SqlDbType.TinyInt, 0)
                    objDB.ExecuteQuery(False)

                    Dim OId As Guid = Guid.NewGuid
                    objDB.AddParameter("CoBroke", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("CoBrokeId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                    InsertTrans_Old(TType, objDB, OId)

                    Dim SListStatus As Integer = 0
                    Select Case ddlTransactType.SelectedValue
                        Case "2"        '--Not for Sale
                            objDB.AddParameter("SListStatus", Data.SqlDbType.TinyInt, 1)
                            SListStatus = 1
                        Case "3"        '--Sale By Owner
                            objDB.AddParameter("SListStatus", Data.SqlDbType.TinyInt, 2)
                            SListStatus = 2
                    End Select
                    InsertIntoProperty_Old("S", SListStatus, 2, "", PropertyUID.ToString, objDB)
                    objDB.dbVariable.SQLString = "UPDATE AW_Property SET STransactionId=@TransactionId, SRelistStatus=@RelistStatus WHERE PropertyId=@PropertyId"
                    objDB.AddParameter("TransactionId", Data.SqlDbType.UniqueIdentifier, TransactionUID)
                    objDB.AddParameter("RelistStatus", Data.SqlDbType.TinyInt, 1)
                    objDB.AddParameter("PropertyId", Data.SqlDbType.UniqueIdentifier, PropertyUID)

                    objDB.ExecuteQuery()
                    objDB.DbTransCommit()
                    objDB.CloseConnection()
                    If Session("PropertyAt") Is Nothing Then
                        Session.Add("PropertyAt", "NFSR")
                    Else
                        Session("PropertyAt") = "NFSR"
                    End If

                    Response.Redirect("transcompletelist.aspx", True)
                    Exit Sub
                    '------ end edition by Tan Chin Teong ------------------------

                    'edited by minginn @ 20/6/2011 - to log property for update status
                    SListStatus = 0
                    Select Case ddlTransactType.SelectedValue
                        Case "2"        '--Not for Sale
                            objDB.AddParameter("SListStatus", Data.SqlDbType.TinyInt, 1)
                            SListStatus = 1
                        Case "3"        '--Sale By Owner
                            objDB.AddParameter("SListStatus", Data.SqlDbType.TinyInt, 2)
                            SListStatus = 2
                    End Select
                    InsertIntoProperty_Old("S", SListStatus, 2, "", PropertyUID.ToString, objDB)
                    objDB.dbVariable.SQLString = "UPDATE AW_Property SET SRelistStatus=@RelistStatus WHERE PropertyId=@PropertyId"


                    'edited by minginn @ 23/5/2011 - to auto relist the not for sale/rent or rent/sale by owner case as this not consider as transaction
                    objDB.AddParameter("RelistStatus", Data.SqlDbType.TinyInt, DBNull.Value)
                    objDB.AddParameter("PropertyId", Data.SqlDbType.UniqueIdentifier, PropertyUID)
                    objDB.ExecuteQuery()

                    'edited by minginn @ 9/6/2011 - to update all fields that should recycle after relist
                    objDB.dbVariable.SQLString = "UPDATE AW_Property SET ListType=@ListType,OwnerName=@OwnerName, OwnerMobile=@OwnerMobile,OwnerPhone=@OwnerPhone,OwnerFax=@OwnerFax,OwnerEmail=@OwnerEmail,OwnerAddress=@OwnerAddress, " & _
                                                         "LandlordName=@LandlordName,LandlordMobile=@LandlordMobile,LandlordPhone=@LandlordPhone,LandlordFax=@LandlordFax,LandlordEmail=@LandlordEmail,LandlordAddress=@LandlordAddress, " & _
                                                         "RRelistStatus=@RListStatus,SRelistStatus=@SListStatus,RTransactionId=@RTransactionId,STransactionId=@STransactionId,CreateDate=@CreateDate,UpdateDate=@UpdateDate,UpdateWho=@UpdateWho, " & _
                                                         "SListerId=@SListerId, RListerId=@RlisterId, " & _
                                                         "SRAmt=@SRAmt,SRPSF=@SRPSF,SRAskAmt=@SRAskAmt,SRAskPSF=@SRAskPSF,SRCreateDate=@SRCreateDate,SRYes=@SRYes, " & _
                                                         "SCAmt=@SCAmt,SCPSF=@SCPSF,SCAskAmt=@SCAskAmt,SCAskPSF=@SCAskPSF,SCCreateDate=@SCCreateDate,SCYes=@SCYes, " & _
                                                         "SLAmt=@SLAmt,SLPSF=@SLPSF,SLAskAmt=@SLAskAmt,SLAskPSF=@SLAskPSF,SLCreateDate=@SLCreateDate,SLYes=@SLYes, " & _
                                                         "SIAmt=@SIAmt,SIPSF=@SIPSF,SIAskAmt=@SIAskAmt,SIAskPSF=@SIAskPSF,SICreateDate=@SICreateDate,SIYes=@SIYes, " & _
                                                         "RRAmt=@RRAmt,RRPSF=@RRPSF,RRAskAmt=@RRAskAmt,RRAskPSF=@RRAskPSF,RRCreateDate=@RRCreateDate,RRYes=@RRYes, " & _
                                                         "RCAmt=@RCAmt,RCPSF=@RCPSF,RCAskAmt=@RCAskAmt,RCAskPSF=@RCAskPSF,RCCreateDate=@RCCreateDate,RCYes=@RCYes, " & _
                                                         "RLAmt=@RLAmt,RLPSF=@RLPSF,RLAskAmt=@RLAskAmt,RLAskPSF=@RLAskPSF,RLCreateDate=@RLCreateDate,RLYes=@RLYes, " & _
                                                         "RIAmt=@RIAmt,RIPSF=@RIPSF,RIAskAmt=@RIAskAmt,RIAskPSF=@RIAskPSF,RICreateDate=@RICreateDate,RIYes=@RIYes  " & _
                                                         "WHERE PropertyId=@PropertyId"
                    objDB.AddParameter("ListType", Data.SqlDbType.TinyInt, DBNull.Value)
                    objDB.AddParameter("OwnerName", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("OwnerMobile", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("OwnerPhone", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("OwnerFax", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("OwnerEmail", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("OwnerAddress", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("LandlordName", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("LandlordMobile", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("LandlordPhone", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("LandlordFax", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("LandlordEmail", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("LandlordAddress", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("PropertyId", Data.SqlDbType.UniqueIdentifier, PropertyUID)
                    objDB.AddParameter("RListStatus", Data.SqlDbType.TinyInt, DBNull.Value)
                    objDB.AddParameter("SListStatus", Data.SqlDbType.TinyInt, DBNull.Value)
                    objDB.AddParameter("SListerId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                    objDB.AddParameter("RListerId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                    objDB.AddParameter("RTransactionId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                    objDB.AddParameter("STransactionId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                    objDB.AddParameter("SRAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SRPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SRAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SRAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SRCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("SRYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("SCAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SCPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SCAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SCAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SCCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("SCYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("SLAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SLPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SLAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SLAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SLCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("SLYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("SIAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SIPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SIAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SIAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SICreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("SIYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("RRAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RRPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RRAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RRAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RRCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("RRYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("RCAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RCPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RCAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RCAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RCCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("RCYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("RLAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RLPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RLAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RLAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RLCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("RLYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("RIAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RIPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RIAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RIAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RICreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("RIYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("CreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("UpdateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("UpdateWho", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                    objDB.ExecuteQuery()

                    objDB.DbTransCommit()
                    objDB.CloseConnection()
                End If
            ElseIf ddlTransactType.SelectedValue = "5" Or ddlTransactType.SelectedValue = "6" Then
                objDB.InitDbTrans()

                Dim CurrentListType As Integer
                Dim CheckPropertyDT As New Data.DataTable
                'Check if Rent Transaction is at sttus 1
                objDB.dbVariable.SQLString = "SELECT ListType FROM AW_Property WHERE PropertyId=@PropertyId"
                objDB.AddParameter("PropertyId", Data.SqlDbType.UniqueIdentifier, PropertyUID)
                objDB.FillData(CheckPropertyDT, "RentTrans", Database.SQLCommandType.NormalString)

                For Each ReadRow As Data.DataRow In CheckPropertyDT.Rows
                    CurrentListType = ReadRow.Item("ListType")
                Next

                Dim RlistStatus As Integer = 0
                Select Case ddlTransactType.SelectedValue
                    Case "5"        '--Not for Rent
                        objDB.AddParameter("RListStatus", Data.SqlDbType.TinyInt, 1)
                        RlistStatus = 1
                    Case "6"        '--Rent By Owner
                        objDB.AddParameter("RListStatus", Data.SqlDbType.TinyInt, 2)
                        RlistStatus = 2
                End Select

                'edit by Tan Chin Teong @ 28/10/2012 - to transact NFR/RBL
                Dim TransactionUID As Guid = Guid.NewGuid
                Dim TType As String = String.Empty
                objDB.dbVariable.SQLString = "INSERT INTO AW_RentTransaction (TransactionId,PropertyId,TransactDate,TransactRemark,CreateDate,Status,TransactorId,Renewed) VALUES (@TransactionId,@PropertyId,@TransactDate,@TransactRemark,@CreateDate,@Status,@TransactorId,@Renewed)"
                TType = "R"
                objDB.AddParameter("TransactionId", Data.SqlDbType.UniqueIdentifier, TransactionUID)
                objDB.AddParameter("PropertyId", Data.SqlDbType.UniqueIdentifier, PropertyUID)
                objDB.AddParameter("TransactDate", Data.SqlDbType.DateTime, Now)

                objDB.AddParameter("TransactRemark", Data.SqlDbType.NVarChar, "Not For Rent/Rent By Landlord")
                objDB.AddParameter("CreateDate", Data.SqlDbType.DateTime, Now)
                objDB.AddParameter("Status", Data.SqlDbType.TinyInt, 6)
                objDB.AddParameter("TransactorId", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text))
                'add in to differentiate trans from renew button or transact
                objDB.AddParameter("Renewed", Data.SqlDbType.TinyInt, 0)
                objDB.ExecuteQuery(False)

                Dim OId As Guid = Guid.NewGuid
                objDB.AddParameter("CoBroke", Data.SqlDbType.TinyInt, 0)
                objDB.AddParameter("CoBrokeId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                InsertTrans_Old(TType, objDB, OId)

                'edited by minginn @ 20/6/2011 - to insert log into rem_old
                InsertIntoProperty_Old("R", RlistStatus, 2, "", PropertyUID.ToString, objDB)

                'edited by minginn @ 23/5/2011 - to auto relist the not for sale/rent or rent/sale by owner case as this not consider as transaction
                objDB.dbVariable.SQLString = "UPDATE AW_Property SET RRelistStatus=@RelistStatus WHERE PropertyId=@PropertyId"
                objDB.AddParameter("RelistStatus", Data.SqlDbType.TinyInt, DBNull.Value)
                objDB.AddParameter("PropertyId", Data.SqlDbType.UniqueIdentifier, PropertyUID)
                objDB.ExecuteQuery()

                objDB.DbTransCommit()
                objDB.CloseConnection()
                If Session("PropertyAt") Is Nothing Then
                    Session.Add("PropertyAt", "NFSR")
                Else
                    Session("PropertyAt") = "NFSR"
                End If

                Response.Redirect("transcompletelist.aspx", True)
                Exit Sub
                '------ End edit Tan Chin Teong------------

                Dim strAdditionalSQL As String
                If CurrentListType = 3 Then
                    objDB.AddParameter("ListType", Data.SqlDbType.TinyInt, 1)
                    strAdditionalSQL = ""
                Else
                    objDB.AddParameter("ListType", Data.SqlDbType.TinyInt, DBNull.Value)
                    strAdditionalSQL = "CreateDate=@CreateDate,UpdateDate=@UpdateDate,UpdateWho=@UpdateWho, "
                    objDB.AddParameter("CreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("UpdateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("UpdateWho", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                End If

                objDB.dbVariable.SQLString = "UPDATE AW_Property SET ListType=@ListType,LandlordName=@LandlordName,LandlordMobile=@LandlordMobile,LandlordPhone=@LandlordPhone,LandlordFax=@LandlordFax,LandlordEmail=@LandlordEmail,LandlordAddress=@LandlordAddress, " & _
                                        "RRelistStatus=@RListStatus, RListerId=@RListerId, RTransactionId=@RTransactionId, " & strAdditionalSQL & _
                                        "RRAmt=@RRAmt,RRPSF=@RRPSF,RRAskAmt=@RRAskAmt,RRAskPSF=@RRAskPSF,RRCreateDate=@RRCreateDate,RRYes=@RRYes, " & _
                                        "RCAmt=@RCAmt,RCPSF=@RCPSF,RCAskAmt=@RCAskAmt,RCAskPSF=@RCAskPSF,RCCreateDate=@RCCreateDate,RCYes=@RCYes, " & _
                                        "RLAmt=@RLAmt,RLPSF=@RLPSF,RLAskAmt=@RLAskAmt,RLAskPSF=@RLAskPSF,RLCreateDate=@RLCreateDate,RLYes=@RLYes, " & _
                                        "RIAmt=@RIAmt,RIPSF=@RIPSF,RIAskAmt=@RIAskAmt,RIAskPSF=@RIAskPSF,RICreateDate=@RICreateDate,RIYes=@RIYes  " & _
                                        "WHERE PropertyId=@PropertyId"

                objDB.AddParameter("LandlordName", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("LandlordMobile", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("LandlordPhone", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("LandlordFax", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("LandlordEmail", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("LandlordAddress", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("PropertyId", Data.SqlDbType.UniqueIdentifier, PropertyUID)
                objDB.AddParameter("RListStatus", Data.SqlDbType.TinyInt, DBNull.Value)
                objDB.AddParameter("RListerId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                objDB.AddParameter("RTransactionId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                objDB.AddParameter("RRAmt", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RRPSF", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RRAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RRAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RRCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                objDB.AddParameter("RRYes", Data.SqlDbType.TinyInt, 0)
                objDB.AddParameter("RCAmt", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RCPSF", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RCAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RCAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RCCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                objDB.AddParameter("RCYes", Data.SqlDbType.TinyInt, 0)
                objDB.AddParameter("RLAmt", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RLPSF", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RLAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RLAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RLCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                objDB.AddParameter("RLYes", Data.SqlDbType.TinyInt, 0)
                objDB.AddParameter("RIAmt", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RIPSF", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RIAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RIAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("RICreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                objDB.AddParameter("RIYes", Data.SqlDbType.TinyInt, 0)
                'objDB.AddParameter("CreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                'objDB.AddParameter("UpdateDate", Data.SqlDbType.DateTime, DBNull.Value)
                'objDB.AddParameter("UpdateWho", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                objDB.ExecuteQuery()

                objDB.DbTransCommit()
                objDB.CloseConnection()
            ElseIf ddlTransactType.SelectedValue = "7" Then 'delete, edit by Tan Chin Teong @ 20121115

                objDB.dbVariable.SQLString = "SELECT RRelistStatus FROM AW_Property WHERE PropertyId=@PropertyId"
                objDB.AddParameter("PropertyId", Data.SqlDbType.UniqueIdentifier, PropertyUID)
                objDB.FillData(CheckRentTransaction, "RentTrans", Database.SQLCommandType.NormalString)
                For Each ReadRow As Data.DataRow In CheckRentTransaction.Rows
                    RRelistStatus = ReadRow.Item("RRelistStatus").ToString
                Next

                If RRelistStatus = "1" Then
                    divError.Visible = True
                    lblMsgError.Text = "There is a pending RENT transaction. Please either COMPLETE the trasaction or ABORT the transaction"
                    ddlTransactType.SelectedIndex = -1
                    Exit Sub
                Else
                    objDB.InitDbTrans()
                    ' need to insert the AW_Transaction ?? (old maybe)
                    'edited by Tan Chin Teong @27/10/2012 - to trasact NFS/SBO to Transaction Status = 6
                    Dim TType As String = String.Empty
                    Dim TransactionUID As Guid = Guid.NewGuid
                    objDB.dbVariable.SQLString = "INSERT INTO AW_SaleTransaction (TransactionId,PropertyId,TransactDate,TransactRemark,CreateDate,Status,TransactorId) VALUES (@TransactionId,@PropertyId,@TransactDate,@TransactRemark,@CreateDate,@Status,@TransactorId)"
                    TType = "S"
                    objDB.AddParameter("TransactionId", Data.SqlDbType.UniqueIdentifier, TransactionUID)
                    objDB.AddParameter("PropertyId", Data.SqlDbType.UniqueIdentifier, PropertyUID)
                    objDB.AddParameter("TransactDate", Data.SqlDbType.DateTime, Now)

                    objDB.AddParameter("TransactRemark", Data.SqlDbType.NVarChar, "Deleted")
                    objDB.AddParameter("CreateDate", Data.SqlDbType.DateTime, Now)
                    objDB.AddParameter("Status", Data.SqlDbType.TinyInt, 7)
                    objDB.AddParameter("TransactorId", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text))
                    'add in to differentiate trans from renew button or transact
                    objDB.AddParameter("Renewed", Data.SqlDbType.TinyInt, 0)
                    objDB.ExecuteQuery(False)

                    Dim OId As Guid = Guid.NewGuid
                    objDB.AddParameter("CoBroke", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("CoBrokeId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                    InsertTrans_Old(TType, objDB, OId)

                    ' need to update AW_Property To DBNull
                    objDB.dbVariable.SQLString = "UPDATE AW_Property SET ListType=@ListType,OwnerName=@OwnerName, OwnerMobile=@OwnerMobile,OwnerPhone=@OwnerPhone,OwnerFax=@OwnerFax,OwnerEmail=@OwnerEmail,OwnerAddress=@OwnerAddress, " & _
                                     "LandlordName=@LandlordName,LandlordMobile=@LandlordMobile,LandlordPhone=@LandlordPhone,LandlordFax=@LandlordFax,LandlordEmail=@LandlordEmail,LandlordAddress=@LandlordAddress, " & _
                                     "RRelistStatus=@RListStatus,SRelistStatus=@SListStatus,RTransactionId=@RTransactionId,STransactionId=@STransactionId,CreateDate=@CreateDate,UpdateDate=@UpdateDate,UpdateWho=@UpdateWho, " & _
                                     "SListerId=@SListerId, RListerId=@RlisterId, SCreateDate=@SCreateDate, RCreateDate=@RCreateDate, " & _
                                     "SRAmt=@SRAmt,SRPSF=@SRPSF,SRAskAmt=@SRAskAmt,SRAskPSF=@SRAskPSF,SRCreateDate=@SRCreateDate,SRYes=@SRYes, " & _
                                     "SCAmt=@SCAmt,SCPSF=@SCPSF,SCAskAmt=@SCAskAmt,SCAskPSF=@SCAskPSF,SCCreateDate=@SCCreateDate,SCYes=@SCYes, " & _
                                     "SLAmt=@SLAmt,SLPSF=@SLPSF,SLAskAmt=@SLAskAmt,SLAskPSF=@SLAskPSF,SLCreateDate=@SLCreateDate,SLYes=@SLYes, " & _
                                     "SIAmt=@SIAmt,SIPSF=@SIPSF,SIAskAmt=@SIAskAmt,SIAskPSF=@SIAskPSF,SICreateDate=@SICreateDate,SIYes=@SIYes, " & _
                                     "RRAmt=@RRAmt,RRPSF=@RRPSF,RRAskAmt=@RRAskAmt,RRAskPSF=@RRAskPSF,RRCreateDate=@RRCreateDate,RRYes=@RRYes, " & _
                                     "RCAmt=@RCAmt,RCPSF=@RCPSF,RCAskAmt=@RCAskAmt,RCAskPSF=@RCAskPSF,RCCreateDate=@RCCreateDate,RCYes=@RCYes, " & _
                                     "RLAmt=@RLAmt,RLPSF=@RLPSF,RLAskAmt=@RLAskAmt,RLAskPSF=@RLAskPSF,RLCreateDate=@RLCreateDate,RLYes=@RLYes, " & _
                                     "RIAmt=@RIAmt,RIPSF=@RIPSF,RIAskAmt=@RIAskAmt,RIAskPSF=@RIAskPSF,RICreateDate=@RICreateDate,RIYes=@RIYes  " & _
                                     "WHERE PropertyId=@PropertyId"

                    objDB.AddParameter("ListType", Data.SqlDbType.TinyInt, DBNull.Value)
                    objDB.AddParameter("OwnerName", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("OwnerMobile", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("OwnerPhone", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("OwnerFax", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("OwnerEmail", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("OwnerAddress", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("LandlordName", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("LandlordMobile", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("LandlordPhone", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("LandlordFax", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("LandlordEmail", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("LandlordAddress", Data.SqlDbType.NVarChar, DBNull.Value)
                    objDB.AddParameter("PropertyId", Data.SqlDbType.UniqueIdentifier, PropertyUID)
                    objDB.AddParameter("RListStatus", Data.SqlDbType.TinyInt, DBNull.Value)
                    objDB.AddParameter("SListStatus", Data.SqlDbType.TinyInt, DBNull.Value)
                    objDB.AddParameter("SListerId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                    objDB.AddParameter("RListerId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                    objDB.AddParameter("RTransactionId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                    objDB.AddParameter("STransactionId", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                    objDB.AddParameter("SRAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SRPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SRAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SRAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SRCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("SRYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("SCAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SCPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SCAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SCAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SCCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("SCYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("SLAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SLPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SLAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SLAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SLCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("SLYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("SIAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SIPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SIAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SIAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("SICreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("SIYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("RRAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RRPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RRAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RRAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RRCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("RRYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("RCAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RCPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RCAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RCAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RCCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("RCYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("RLAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RLPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RLAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RLAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RLCreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("RLYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("RIAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RIPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RIAskAmt", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RIAskPSF", Data.SqlDbType.Decimal, DBNull.Value)
                    objDB.AddParameter("RICreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("RIYes", Data.SqlDbType.TinyInt, 0)
                    objDB.AddParameter("CreateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("UpdateDate", Data.SqlDbType.DateTime, DBNull.Value)
                    objDB.AddParameter("UpdateWho", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                    objDB.AddParameter("SCreateDate", Data.SqlDbType.DateTime, DBNull.Value)   'Edited by tanchinteong @26112012
                    objDB.AddParameter("RCreateDate", Data.SqlDbType.DateTime, DBNull.Value)


                    objDB.ExecuteQuery()
                    objDB.DbTransCommit()
                    objDB.CloseConnection()
                    If Session("PropertyAt") Is Nothing Then
                        Session.Add("PropertyAt", "Completed")
                    Else
                        Session("PropertyAt") = "Completed"
                    End If

                End If

            End If

            If ddlTransactType.SelectedValue <> "7" Then
                Response.Redirect("propertylist.aspx", False)
            Else
                Response.Redirect("TransHistory.aspx", False)
            End If

        Catch ex As Exception
            If objDB.dbVariable.objConn.State = Data.ConnectionState.Open Then
                objDB.DbTransRollback()
            End If
            objDB.CloseConnection()
            lblMsgError.Text = ex.Message
            divError.Visible = True
        End Try
    End Sub

    Private Sub InsertIntoProperty_Old(ByVal TType As String, ByVal ListStatus As String, ByVal RelistStatus As String _
                                       , ByVal TransactionId As String, ByVal PropertyUID As String, ByVal objdb As Database)
        Dim strListStatus As String
        Dim strRelistStatus As String
        Dim strTransactionId As String

        If ListStatus = "" Then
            objdb.AddParameter("ListStatusOLD", Data.SqlDbType.TinyInt, DBNull.Value)
        Else
            objdb.AddParameter("ListStatusOLD", Data.SqlDbType.TinyInt, ListStatus)
        End If
        If RelistStatus = "" Then
            objdb.AddParameter("RelistStatusOLD", Data.SqlDbType.TinyInt, DBNull.Value)
        Else
            objdb.AddParameter("RelistStatusOLD", Data.SqlDbType.TinyInt, RelistStatus)
        End If
        If TransactionId <> "" Then
            objdb.AddParameter("TransactionIdOLD", Data.SqlDbType.UniqueIdentifier, New Guid(TransactionId))
        Else
            objdb.AddParameter("TransactionIdOLD", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
        End If

        If TType = "S" Then
            strListStatus = " @ListStatusOLD, RListStatus, "
            strRelistStatus = " @RelistStatusOLD, RRelistStatus, "
            strTransactionId = " @TransactionIdOLD, RTransactionId, "
        Else
            strListStatus = " SListStatus, @ListStatusOLD, "
            strRelistStatus = " SRelistStatus, @RelistStatusOLD, "
            strTransactionId = " STransactionId, @TransactionIdOLD, "
        End If

        objdb.dbVariable.SQLString = "INSERT INTO " + AppSettings("logdatasource").ToString() + ".dbo.AW_Property " & _
            "(OId,PropertyId, RoadId, ProjectId, PropertyTypeId, UnitNumber, ListType, STransactionId, RTransactionId, SRAmt, " & _
            "SRPSF, SRAskAmt, SRAskPSF, SRCreateDate, SRYes, SCAmt, SCPSF, SCAskAmt, SCAskPSF, SCCreateDate, SCYes, SLAmt, " & _
            "SLPSF, SLAskAmt, SLAskPSF, SLCreateDate, SLYes, SIAmt, SIPSF, SIAskAmt, SIAskPSF, SICreateDate, SIYes, RRAmt, " & _
            "RRPSF, RRAskAmt, RRAskPSF, RRCreateDate, RRYes, RCAmt, RCPSF, RCAskAmt, RCAskPSF, RCCreateDate, RCYes, RLAmt, " & _
            "RLPSF, RLAskAmt, RLAskPSF, RLCreateDate, RLYes, RIAmt, RIPSF, RIAskAmt, RIAskPSF, RICreateDate, RIYes, " & _
            "SListerId, RListerId, KeyInOffice, ProjectRemark, PropertyDesc, SignboardStatus, SignboardWhere, SignboardWhen, " & _
            "SurveySheet, QuitRent, AssessmentBill, PendingStatus, PendingWho, PendingWhen, PendingWhy, Tenure, ListHoldExpired, " & _
            "Access, AccessRemark, Condition, ConditionRemark, Facing, Zoning, ZoningRemark, Room, Bathroom, BestBuy, ExclusiveStatus, ExclusiveWho, ExclusiveWhen, ExclusiveEndDate, " & _
            "AuthorizeSaleRent, Remark, Production1, Production2, Production3, Admin1, Admin2, Admin3, LAWidth, LALength, " & _
            "LASF, BUWidth, BULength, BUSF, FloorLoad, SECMK, Ceiling, Terrain, District, Lot, Phase, Furnished, FurnishedRemark, " & _
            "Renovated, RenovatedRemark, Developer, OwnerName, OwnerMobile, OwnerPhone, OwnerFax, OwnerEmail, " & _
            "OwnerAddress, ReferLister, SListStatus, RListStatus, SRelistStatus, RRelistStatus, CreateDate, StatusDelete, UpdateDate, UpdateWho, " & _
            "LandlordName, LandlordMobile, LandlordPhone, LandlordFax, LandlordEmail, LandlordAddress, ReferLandlordLister) " & _
            "SELECT @OId, PropertyId, RoadId, ProjectId, PropertyTypeId, UnitNumber, ListType, " & strTransactionId & "SRAmt, " & _
            "SRPSF, SRAskAmt, SRAskPSF, SRCreateDate, SRYes, SCAmt, SCPSF, SCAskAmt, SCAskPSF, SCCreateDate, SCYes, SLAmt, " & _
            "SLPSF, SLAskAmt, SLAskPSF, SLCreateDate, SLYes, SIAmt, SIPSF, SIAskAmt, SIAskPSF, SICreateDate, SIYes, RRAmt, " & _
            "RRPSF, RRAskAmt, RRAskPSF, RRCreateDate, RRYes, RCAmt, RCPSF, RCAskAmt, RCAskPSF, RCCreateDate, RCYes, RLAmt, " & _
            "RLPSF, RLAskAmt, RLAskPSF, RLCreateDate, RLYes, RIAmt, RIPSF, RIAskAmt, RIAskPSF, RICreateDate, RIYes, " & _
            "SListerId, RListerId, KeyInOffice, ProjectRemark, PropertyDesc, SignboardStatus, SignboardWhere, SignboardWhen, " & _
            "SurveySheet, QuitRent, AssessmentBill, PendingStatus, PendingWho, PendingWhen, PendingWhy, Tenure, ListHoldExpired, " & _
            "Access, AccessRemark, Condition, ConditionRemark, Facing, Zoning, ZoningRemark, Room, Bathroom, BestBuy, ExclusiveStatus, ExclusiveWho, ExclusiveWhen, ExclusiveEndDate, " & _
            "AuthorizeSaleRent, Remark, Production1, Production2, Production3, Admin1, Admin2, Admin3, LAWidth, LALength, " & _
            "LASF, BUWidth, BULength, BUSF, FloorLoad, SECMK, Ceiling, Terrain, District, Lot, Phase, Furnished, FurnishedRemark, " & _
            "Renovated, RenovatedRemark, Developer, OwnerName, OwnerMobile, OwnerPhone, OwnerFax, OwnerEmail, " & _
            "OwnerAddress, ReferLister, " & strListStatus & strRelistStatus & "@CreateDateOLD, StatusDelete, @UpdateDateOLD, @UpdateWhoOLD, " & _
            "LandlordName, LandlordMobile, LandlordPhone, LandlordFax, LandlordEmail, LandlordAddress, ReferLandlordLister " & _
            "FROM AW_Property WHERE PropertyId = @PropertyIdOLD"
        objdb.AddParameter("OId", Data.SqlDbType.UniqueIdentifier, Guid.NewGuid)
        objdb.AddParameter("PropertyIdOLD", Data.SqlDbType.UniqueIdentifier, New Guid(PropertyUID))
        objdb.AddParameter("CreateDateOLD", Data.SqlDbType.DateTime, Now())
        objdb.AddParameter("UpdateDateOLD", Data.SqlDbType.DateTime, DBNull.Value)
        objdb.AddParameter("UpdateWhoOLD", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text))
        objdb.ExecuteQuery(False)

    End Sub

    Private Sub InsertTrans_Old(ByVal TType As String, ByVal objdb As Database, ByVal OId As Guid)
        Dim strDB As String
        If TType = "S" Then
            strDB = "" + AppSettings("logdatasource").ToString() + ".dbo.AW_SaleTransaction"
        Else
            strDB = "" + AppSettings("logdatasource").ToString() + ".dbo.AW_RentTransaction"
        End If
        objdb.dbVariable.SQLString = "INSERT INTO " & strDB & "(OId,TransactionId,PropertyId,TransactDate, " & _
                                    "TransactRemark,CreateDate,Status,CoBroke,CoBrokeId,TransactorId,UpdateWho) " & _
                                    "VALUES (@OId,@TransactionId,@PropertyId,@TransactDate,@TransactRemark, " & _
                                    "@CreateDateOLD,@Status,@CoBroke,@CoBrokeId,@TransactorId,@UpdateWho)"
        objdb.AddParameter("OId", Data.SqlDbType.UniqueIdentifier, OId)
        objdb.AddParameter("CreateDateOLD", Data.SqlDbType.DateTime, Now())
        objdb.AddParameter("UpdateWho", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text))
        objdb.ExecuteQuery()

    End Sub

    Protected Sub btnBack_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBack.Click
        Dim strBack As String = Session("Back").ToString
        Dim arr() As String = strBack.Split("ڡ")
        Response.Redirect(arr(0).ToString)
    End Sub
End Class
